package com.example.demo.arithmetic.datastructure.linkedlist;

import org.junit.Test;
import java.sql.SQLOutput;

/**
 * @Description: 手动实现单链表
 * @Author: LLL
 * @Date: 2020-03-13 19:43
 **/
public class SingleLinkedListDemo {

    public static void main(String[] args) {
        // 创建节点
        HeroNode node1 = new HeroNode("宋江", "及时雨", 1);
        // 创建节点
        HeroNode node2 = new HeroNode("卢俊义", "玉麒麟", 2);
        // 创建节点
        HeroNode node3 = new HeroNode("吴用", "智多星", 3);
        // 创建节点
        HeroNode node4 = new HeroNode("林冲", "豹子头", 4);

        SingleLinkedList linkedList = new SingleLinkedList();
        //        linkedList.add(node2);
        //        linkedList.add(node3);
        //        linkedList.add(node1);
        //        linkedList.add(node4);

        linkedList.addByOrder(node2);
        linkedList.addByOrder(node3);
        linkedList.addByOrder(node1);
        linkedList.addByOrder(node4);
        linkedList.list();
        //        System.out.println("修改后节点为");
        // 创建节点
        HeroNode node5 = new HeroNode("林冲2", "豹子头3", 5);
        //        linkedList.update(node5);
        //        linkedList.list();
        // 删除
        //        System.out.println("删除节点：");
        //        linkedList.delete(node3);
        //        linkedList.list();
        System.out.println(linkedList.size());
        HeroNode lastM = linkedList.getLastM(4);
        System.out.println("获取到倒数第m个:" + lastM);
        linkedList.list();
    }

    @Test
    public void testReverse() {
        // 创建节点
        HeroNode node1 = new HeroNode("宋江", "及时雨", 1);
        // 创建节点
        HeroNode node2 = new HeroNode("卢俊义", "玉麒麟", 2);
        // 创建节点
        HeroNode node3 = new HeroNode("吴用", "智多星", 3);
        // 创建节点
        HeroNode node4 = new HeroNode("林冲", "豹子头", 4);
        SingleLinkedList linkedList = new SingleLinkedList();
        linkedList.addByOrder(node2);
        linkedList.addByOrder(node3);
        linkedList.addByOrder(node1);
        linkedList.addByOrder(node4);
        linkedList.list();
        System.out.println("翻转后链表如下：");
        linkedList.reverse();
        linkedList.list();
    }

    @Test
    public void testReverseList() {
        // 创建节点
        HeroNode node1 = new HeroNode("宋江", "及时雨", 1);
        // 创建节点
        HeroNode node2 = new HeroNode("卢俊义", "玉麒麟", 2);
        // 创建节点
        HeroNode node3 = new HeroNode("吴用", "智多星", 3);
        // 创建节点
        HeroNode node4 = new HeroNode("林冲", "豹子头", 4);
        SingleLinkedList linkedList = new SingleLinkedList();
        linkedList.addByOrder(node2);
        linkedList.addByOrder(node3);
        linkedList.addByOrder(node1);
        linkedList.addByOrder(node4);
        linkedList.list();
        System.out.println("翻转打印：");
        linkedList.listFromRear();

        String s = " ";
        boolean matches = s.matches("\\s");
        System.out.println(matches);
    }
}



